Fix quantized Conv1d same padding with even kernels in XNNPACK#20734
Fix quantized Conv1d same padding with even kernels in XNNPACK#20734SakshamKapoor2911 wants to merge 5 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20734
Note: Links to docs will display an error until the docs builds have been completed.
|
|
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an XNNPACK delegation/runtime correctness issue for statically-quantized nn.Conv1d(padding="same") with even kernel sizes by folding the explicit temporal constant_pad_nd into asymmetric Conv2d padding during Conv1d→Conv2d lowering, and ensuring the serialized graph’s metadata matches the folded asymmetric padding.
Changes:
- Extend XNNPACK partitioning and Conv1d unsqueeze lowering to absorb temporal-only zero
constant_pad_ndinto the quantized Conv1d partition and fold it into asymmetricxnnpack_input_padding. - Teach Conv2d serialization to use folded asymmetric padding metadata when present, and add a late pass to repair Conv1d folded-pad tensor metadata after retracing passes.
- Add a regression test covering quantized Conv1d even-kernel
padding="same".
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backends/xnnpack/test/ops/test_conv1d.py | Adds a regression test for quantized Conv1d even-kernel padding="same" and factors out calibration sample generation. |
| backends/xnnpack/partition/config/gemm_configs.py | Extends convolution activation-dependency discovery to include temporal-only zero constant_pad_nd for quantized Conv1d so it can be partitioned/delegated. |
| backends/xnnpack/operators/op_conv2d.py | Uses folded asymmetric xnnpack_input_padding metadata (top/right/bottom/left) when present instead of symmetric ATen padding args. |
| backends/xnnpack/_passes/conv1d_unsqueeze_pass.py | Folds eligible temporal-only constant_pad_nd into asymmetric input padding during Conv1d→Conv2d lowering and adds a pass to restore correct tensor metadata for folded-pad Conv1d. |
| backends/xnnpack/_passes/init.py | Registers the new folded-pad metadata repair pass in the default XNNPACK pass pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
❌ 🤖 pytorchbot command failed: |
|
@pytorchbot label "release notes: xnnpack" |
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
43c6c72 to
529a792
Compare
529a792 to
619ae4c
Compare
|
The PR for 2D has landed: You can take the same approach here; have an explicit PAD op, which gets executed in XNNPACK. We can then later fold that XNNPACK pad in the delegated graph, this is a follow up to both of these PRs. As is, this code will also fail on: |
|
Addressed review feedback: adopted the same approach as #20553 — keep the Changes:
The pad can be folded in the delegated graph later as a follow-up optimization (per the review suggestion). |
|
I believe you need to rebase and make sure the commit I shared is landed in your branch, there are merge conflicts from duplicated code |
approach) Instead of folding constant_pad_nd into asymmetric Conv2d padding, keep it as an explicit XNNPACK pad op: - Remove pad-folding logic from Conv1dUnsqueezePass - Remove Conv1dFoldedPadMetaPass (no longer needed) - Revert xnnpack_input_padding handling in op_conv2d.py - Add InsertPadQDQPass: inserts QDQ after pad in quantized contexts so it serializes as a quantized static pad This matches the approach from pytorch#20553 and fixes the crash with conv1d -> flatten (even kernel + same padding).
3b7443f to
bf3644f
Compare
|
Rebased onto current main and resolved the duplicated-code conflict. The conflict was an add/add in |
|
Please setup and run lintrunner to resolve the failures. See https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#lintrunner Also it seems like you've duplicated the get act dep in Gemm config instead of only updating as necessary. I have not fully reviewed but I did notice that your comment said it kept the existing pad pass but the commit has substantial changes to it. |
Refactor InsertPadQDQPass with guard checks (pad_value, pad_amounts, negative amounts) and correct idempotency (re-add is_quant check). Use is_dequant instead of matching specific dequant target. Add super().call() retrace to update graph_module metadata. Merge duplicated _get_act_deps in ConvolutionConfig — handle both 1D and 2D convs with their respective pad constraints. Also follow QDQ chain (dequant -> pad -> q -> dq -> conv) when InsertPadQDQPass has already inserted a quantize/dequantize pair after the pad. Restore XNNPACK pass ordering in __init__.py and Conv1dUnsqueezePass variable scoping to match origin/main (no functional change). Add regression test for quantized Conv1d even-kernel same-padding covering both symmetric and asymmetric pad cases. Co-authored-by: Claude
|
Addressed the remaining review points: Lint: Gemm config
|
|
@claude please review |
|
Claude finished @JakeStevens's task in 7m 9s —— View job Review — PR #20734: Fix quantized Conv1d same padding with even kernels
Overall this is a clean adoption of the explicit-PAD approach from #20553 and reads much better than the earlier pad-folding version. The transposed-conv gating and idempotency concerns from earlier rounds are addressed. A few things worth a look before merge: 1.
|
Fixes #20558.
Related to #20553.
Summary
Quantized
nn.Conv1d(..., padding="same")with an even kernel exports withasymmetric padding (unequal left/right amounts), which cannot be folded into
the convolution's symmetric padding field. The original pad-folding approach
in this PR was replaced with the explicit-PAD approach from #20553:
constant_pad_nd nodes in quantized contexts so they serialize as quantized
static pads. Refactored with additional guard checks (pad_value, pad_amounts,
negative amounts) and correct idempotency.
(and their QDQ chain if InsertPadQDQPass already ran) into the convolution's
partition for both 1D and 2D convs. The merged method replaces separate 1D
and 2D implementations that existed on this branch.
symmetric and asymmetric pad cases, validated by numerical comparison.
changes.
With these changes, an even-kernel
padding="same"conv1d graph:becomes (after XNNPACK preprocessing and partitioning):
Test plan
cc @GregoryComer @digantdesai @cbilgin @JakeStevens @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani